package fr.cephb.lang;

import java.io.Serializable;

/** A class for handling an unsigned int 32 */
public class UInt32
implements Comparable<UInt32>,Serializable,Cloneable
{
private static final long serialVersionUID = 1L;

/** internal value expressed as a Long */
private long value;
/**  MAX_VALUE */
public final static long MAX_VALUE = 0xffffffffL;

/**  MIN_VALUE */
public final static long MIN_VALUE = 0;

/** constructor with a long */
public UInt32(long value)
	{
	if(value<MIN_VALUE) throw new NumberFormatException("key shouldn't be lower than "+MIN_VALUE);
	if(value>MAX_VALUE) throw new NumberFormatException("key shouldn't be greater than "+MAX_VALUE);
	this.value=value;
	}

/** constructor = 0 */
public UInt32()
	{
	this(0L);
	}

/** copy constructor */
public UInt32(UInt32 cp)
	{
	this(cp.value);
	}

/** constructor invoking Long.parseLong */
public UInt32(String text)
	{
	this(Long.parseLong(text));
	}

@Override
public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + (int) (value ^ (value >>> 32));
	return result;
}
@Override
public boolean equals(Object obj) {
	if (this == obj)
		return true;
	if (obj == null)
		return false;
	if (getClass() != obj.getClass())
		return false;
	UInt32 other = (UInt32) obj;
	if (value != other.value)
		return false;
	return true;	
	}

@Override
public int compareTo(UInt32 o)
	{
	long n= this.value-o.value;
	return n==0L?0:n<0L?-1:1;
	}

/** return this a a long */
public long longValue()
	{
	return this.value;
	}

@Override
public Object clone()
	{
	return new UInt32(this);
	}

@Override
public String toString()
	{
	return String.valueOf(this.value);
	}

/** parses a UInt32 as a String */
public static UInt32 	valueOf(java.lang.String s)
	{
	return new UInt32(s);
	}
}
